package controler.consultation;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.SystemColor;
import java.util.List;

import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

import controler.News;
import model.dao.*;

public class ConsultNews {
	
	public void afficherTopTen(JPanel contentPane, Boolean mode) {
		contentPane.setVisible(false);
		List<News> listNews = NewsDAO.selectAll(10);
		for (News news : listNews) {
			JPanel panelNew = new JPanel();
			panelNew.setAlignmentX(FlowLayout.LEFT);
			panelNew.setBorder(new EmptyBorder(0, 15, 10, 0));
			panelNew.setPreferredSize(new Dimension(10, 30));	
			panelNew.setLayout(new BoxLayout(panelNew, BoxLayout.X_AXIS));
			JLabel label = new JLabel(news.getLibelle() + " - " + news.getDescription());
			panelNew.add(label);		
			if (mode) {
				JButton link = new JButton("+");
				link.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
				link.setContentAreaFilled(false);
				link.setBorderPainted(false);
				link.setBackground(SystemColor.info);
				link.setEnabled(false);
				link.setMaximumSize(new Dimension(25, 15));
				link.setForeground(Color.BLUE);
				panelNew.add(link);
			}
			contentPane.add(panelNew);
		}
		contentPane.setVisible(true);
	}
}
